using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Medianamik.Core;
using Telerik.Web.UI;
using Medianamik.UI.Controls;
using Medianamik.UI.Lock;
using Medianamik.Core.Sugar;
using Medianamik.Core.Security;

namespace Medianamik.UI.SecurityManagement
{
    public partial class PermissionList : BasePage
    {

        #region Fields



        #endregion

        #region Events

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                #region NodeClicked

                if (!String.IsNullOrEmpty(Request[PostBackConstants.PostBackEventTarget])
                    && Request[PostBackConstants.PostBackEventTarget].Equals(NodePermissionSelector.ClientID))
                {
                    Guid selectedNodeId;

                    if (StringHelper.IsGuid(Request[PostBackConstants.PostBackEventArgument], out selectedNodeId))
                        LoadPermissionsForSelectedNode(selectedNodeId);
                    else
                        NodePermissionSelector.Visible = false;
                }

                #endregion
            }
            else
            {
                LoadRootNodesForFullArboTree();
                LoadAllNodesSecurityPreviewTree();
            }
        }

        #endregion

        #region Properties



        #endregion

        #region Methods

        private void LoadPermissionsForSelectedNode(Guid selectedNodeId)
        {
            NodePermissionSelector.SecuredObjectId = selectedNodeId;
            NodePermissionSelector.DataBind();
        }

        private void LoadRootNodesForFullArboTree()
        {
            FullArboTree.Nodes.AddRange(NodeManager
                .GetRootNodes().Select(n =>
                    n.ToRadTreeNode(CurrentUICulture.Name, TreeNodeExpandMode.WebService)));

        }

        private void LoadAllNodesSecurityPreviewTree()
        {
            //SecurityManager.
        }

        #endregion

    }
}
